<%@page import="controller.CartContr"%>
<%@page import="model.entity.Orders"%>
<%@page import="java.util.ArrayList"%>
<%@page import="model.entity.OrderDetails"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="kendo" uri="http://www.kendoui.com/jsp/tags"%>    
    <script type="text/javascript">
	    $(function() {
	    	$("#cartTogBut").button({
	            icons: {
	                primary: "ui-icon-circle-arrow-n"
	            },
	            text: false
	        });	
	    	$("#checkOutBut").button({ icons: { primary: "ui-icon-play" }});	    	
	    	$("#delFromCart").button({ icons: { primary: "ui-icon-circle-close" }});
	    	$("#cartTogButTd").bind("click",function() {
	    		$("#cartDiv").toggleClass('hideCart');
	    		$(this).toggleClass('ui-icon-circle-arrow-s');
	    	});
	    });
    </script>
			<%
				ArrayList<OrderDetails> cart = (ArrayList<OrderDetails>) session.getAttribute("cart");
				if(cart == null) cart = new ArrayList<OrderDetails>();
				
				String idProduct = request.getParameter("idProduct");
				String command = request.getParameter("command");
				if(idProduct != null) {
					CartContr.addProductToCart(Integer.parseInt(idProduct), session);
					cart = (ArrayList<OrderDetails>) session.getAttribute("cart");
				}
				if(command != null) {
					//CartContr.removeProductToCart(Integer.parseInt(idProduct), session);
					//cart = (ArrayList<OrderDetails>) session.getAttribute("cart");
				}
			%>
			<table>
				<tr id="cartHeader">
					<td>
					
					<div id="cartEdit" style="width: 100%; text-align: center;">
						<!--<jsp:include page="ajaxTest.jsp"></jsp:include> -->
					</div>
					
					</td>
					<td id="cartShortInfo">
						<table>
							<tr>
								<td style="width: 30%;"><%=Orders.sumQuantity(cart)%> món hàng.</td>
								<td>Tổng tiền: <%=Orders.sumMoneyS(cart)%></td>
							</tr>
						</table>
					</td>
					<td id="cartTogButTd">
						<% if (cart.size() > 0) {%>
						<button id="cartTogBut">&nbsp;</button>
						<%} %>
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<div id="mainCart">
							<table id="smallCart">
								<tr>
									<td>
										<div style="width: 100%; overflow: hidden;">
										<ul id="listProduct">
										<% for(OrderDetails details : cart) { %>
											<li>
												<table class="liSanPham slowTrans" onclick="showEditCart(<%=details.getProduct().getProductId()%>)">
													<tr>
														<td>
															<img alt="" src="../<%=details.getProduct().getImage() %>" class="smallCarImg"/>
															<div class="quantityFl"><%=details.getQuantity() %> </div>
															<div class="clear"></div>
														</td>
													</tr>
													<tr>	
														<td>
															<%=details.totalMoney() %>Đ
														</td>
													</tr>
												</table>
											</li>
										<% } %>
										</ul>
										</div>
									</td>
									<td style="width: 344px;text-align: center;">
										<a id="checkOutBut" href="checkOutModule.jsp">Thanh Toán</a>
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
			</table>
